// Copyright (C) 2025 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#if !defined( __cpp_exceptions ) || !defined( _POSIX_MAPPED_FILES )
#include <iostream>
int main()
{
   std::cout << "Exception support disabled, skipping test..." << std::endl;
}
#else

#include <rothar/pegtl/file_input.hpp>

#include "test.hpp"

namespace rothar
{
   void unit_test()
   {
      try {
         internal::file_mapper dummy( "include" );
         // LCOV_EXCL_START
         std::cerr << "pegtl: unit test failed for [ internal::file_mapper ]" << std::endl;
         ++failed;
         // LCOV_EXCL_STOP
      }
      catch( const internal::filesystem::filesystem_error& ) {
      }
      // LCOV_EXCL_START
      catch( ... ) {
         std::cerr << "pegtl: unit test failed for [ internal::file_mapper ] with unexpected exception" << std::endl;
         ++failed;
      }
      // LCOV_EXCL_STOP

      const std::string s = "dummy content\n";
      const std::string dummy_content = s + s + s + s + s + s + s + s + s + s + s;

      internal::file_mapper mapper( "tests/file_data.txt" );
      ROTHAR_PEGTL_TEST_ASSERT( !mapper.empty() );
      ROTHAR_PEGTL_TEST_ASSERT( mapper.size() == 154 );
      ROTHAR_PEGTL_TEST_ASSERT( std::string_view( mapper.data(), mapper.size() ) == dummy_content );
      ROTHAR_PEGTL_TEST_ASSERT( std::string_view( mapper.begin(), mapper.end() - mapper.begin() ) == dummy_content );
   }

}  // namespace rothar

#include "main.hpp"

#endif
